package com.itheima.controller;

/**
 * @Description: ClazzController
 * @Author: HH
 * @Date: 2025/4/19 10:30
 **/

import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班级管理controller
 */
@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    private Integer two; // 定义一个变量

    /**
     * 条件分页查询-请求参数封装
     */
    @GetMapping
    public Result page(ClazzQueryParam param) {
        log.info("请求参数： {}", param);
        PageBean pageBean = clazzService.page(param);
        return Result.success(pageBean);
    }


    /**
     * 添加班级
     */
    @PostMapping
    public Result insert(@RequestBody Clazz clazz) {
        log.info("添加班级: {}", clazz);
        clazzService.insert(clazz);
        return Result.success();
    }

    /**
     * 根据ID查询班级信息
     */
    @GetMapping("/{id:\\d+}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("根据ID查询班级信息: {}", id);
        Clazz clazz = clazzService.getInfo(id);
        return Result.success(clazz);
    }

    /**
     * 修改班级信息
     * @param clazz
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("修改班级信息: {}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有班级");
        return Result.success(clazzService.list());

    }

    /**
     * 删除班级
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        clazzService.delete(id);
        return Result.success();
    }

}
